#!/usr/bin python
# -*- coding: utf-8 -*-
# @Time    : 2023/6/16 17:49
# @Author  : hhr
import time, os, requests, json, xlrd

from openpyxl import load_workbook


class upload_pdf_file():
    def __init__(self):
        self.token = self.t_login()

    def t_login(self):
        headers = {"Accept": "application/json", }
        url = "https://api.xinhehonggu.com/api/auth/login"
        phone = '18866668888'
        password = 'xhhg2019'
        source = 'admin'
        data = {
            'phone': phone,
            'password': password,
            'source': source,
        }

        r = requests.post(url=url, data=data, headers=headers, verify=False)

        res = r.text

        res_dict = json.loads(res)
        token = res_dict['data']['token']
        return token

    def read_excel(self, path):
        wb = load_workbook(r"D:\Users\PycharmProjects\djangoProject\DecompressDailyCPCFiles\20230616\PDF\办理登记\今日需上传办登.xlsx")
        a_sheet = wb.get_sheet_by_name('Sheet1')
        cell_2_2 = a_sheet.cell(row=2, column=2)
        cell_2_2_value = a_sheet.cell(row=2, column=2).value
        print('第2行第2列', cell_2_2)
        print('第2行第2列值', cell_2_2_value)


    def UploadAuthorizationNotice(self, file_path):
        """ 上传授权通知书 """
        # =============================== 构建上传参数 ===============================
        headers = {"Accept": "application/json"}
        url = 'http://112.125.25.114:90/api/finals/acceptance_file'
        data = {'token': self.token, 'marks': '1'}

        # =============================== 读取今日需上传办登表 ===============================
        excel_path = os.path.join(file_path, "今日需上传办登.xlsx")
        self.read_excel(excel_path)  # 读取办登表格里的数据



    def main_func(self):
        date = time.strftime("%Y%m%d")
        # date = '22222222'
        cur_file = os.getcwd()  # 当前工作路径
        pathZip = os.path.join(cur_file, date)  # 拼接路径并创建
        pdf_main_path = os.path.join(pathZip, "PDF")
        st_path = pdf_main_path + '\办理登记'
        self.UploadAuthorizationNotice(st_path)


if __name__ == '__main__':
    upload_pdf_file().main_func()